package view;

import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.ResourceBundle;

import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;

/**
 * @author Andrea
 * 
 */
public class HistoryArea {
	private static ResourceBundle myViewLabels = ResourceBundle
			.getBundle("resources.englishView");
	private static ResourceBundle myViewSizes = ResourceBundle
			.getBundle("resources.viewSizes");

	private static ArrayList<String> activeHistory = new ArrayList<String>();
	private static JTextArea historyBox;
	private JPanel historyPanel;
	private static final String newline = "\n";

	public JPanel historyBox() {
		// Create the panel
		historyPanel = new JPanel(new BorderLayout());

		// Create the text box that goes in it
		GeneralTextArea in = new GeneralTextArea();
		historyBox = in.makeTextField(myViewLabels.getString("HistoryPanel"),
				Integer.parseInt(myViewSizes.getString("HistoryFieldRows")),
				ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, false);

		historyPanel.add(historyBox, BorderLayout.CENTER);
		return historyPanel;
	}

	// Updates the entire history panel (necessary to update the whole thing
	// because we have multiple tabs, each with a different history.
	public static void updateHistoryPanel(ArrayList<String> commands) {
		historyBox.setText("");
		for (int i = 0; i < commands.size(); i++) {
				historyBox.append(commands.get(i));
				historyBox.append(newline);
			}
		
}

	public static void changeActiveHistory(ArrayList<String> current) {
		activeHistory = current;
	}

	public static ArrayList<String> getActiveHistory() {
		return activeHistory;
	}

	public static void addToHistory(String expression) {
		activeHistory.add(expression);
		updateHistoryPanel(activeHistory);
	}
}
